package tmp

import scala.reflect.runtime.universe._
import scala.collection.mutable.ArraySeq
import scala.collection.mutable.Seq
import util.StopWatch
import scala.collection.mutable.ListBuffer
import scala.util.Random

object OtherApp extends App {

  def p(any: Any) = println(any)

  def stopWatch[A](fn: => A)(implicit mock: Boolean) = StopWatch { if (mock) p(fn) } { t => p(s"${t}ms") }

  implicit val mock = false

  
  p((new Random(5)).nextInt(10))
  
  val a = new Array[String](5)
  
  p((3.1415926).floor)
  
  for(i <- 0 to 4) {
    a(i) = i+"--"
  }
  
  println(a.toList)
  
//  val const = 500000000
   val const = 5
    val list = (0 to const).toList
  
    stopWatch {
      list.map(i => i + "").size
    }
  
    val listBuf = new ListBuffer[Int]
    
    stopWatch {
      list.foreach(i => listBuf.append(i))
      listBuf.size
    }

  stopWatch {
	  for (i<- 0 to const){ 
	    i.getClass.getName()
	     Random.nextInt(99999).toString
	  }
  }

  stopWatch {
    var i = 0
    while (i != const){
      i.getClass.getName()
      Random.nextInt(99999).toString
      i +=1
    }
  }
  
  def partial1[A, B, C](a: A, f: (A, B) => C): B => C = b => f(a, b)

  p(partial1(1, (a: Int, b: String) => b.length + a).apply("123"))
  
  
  import scala.collection.mutable

  val b = new mutable.StringBuilder("Hello")
  def e = b.length

  def p0 = {
    val l1 = e
    val l2 = e
    l1 + l2
  }

  def p1 = {
    val l1 = e
    b.append("World")
    val l2 = e
    l1 + l2
  }
  
  
  p(p0, p1,p0 == p1)
  
  
 val set = Set("2","4","5")
  p(set.take(5))
  p(Random.shuffle(set))

}